<template>
	<view class="container">
		<view style="padding: 30rpx;font-size: 32rpx;font-weight: bold;">付款给 {{shopName}}</view>
		<view class="confirmPayMoney">
			<!-- <text style="font-size: 24rpx;color: #666666;margin-bottom: 20rpx;">当前购物积分余额{{userInfo.incomes}}</text> -->
			<text class="title">付款金额</text>
			<view class="input_con">
				<text>¥</text>
				<input type="digit" :value="totalPrice" @input="payMoneyChange" placeholder="请输入付款金额" placeholder-style="font-size: 36rpx" maxlength='10' confirm-type='done'/>
			</view>
			<text style="color: red;font-size: 26rpx;" v-if="!totalPricePass">{{priceRule}}</text>
		</view>
		<!-- 支付方式 -->
		<view class="payWay">
			<view class="jifen">
				<text>购物积分支付（可用{{userInfo.incomes}}）</text>
				<u-switch activeColor='#d4a781' v-model="isIncomes" @change="paywayChange('isIncomes')"></u-switch>
			</view>
			<view style="margin-left: 26rpx;color: #d4a781;font-size: 24rpx;margin-bottom: 10rpx;">提示：积分和微信支付不可叠加使用！</view>
		</view>
		<view style="background-color: #FFF;display: flex;flex-direction: row;align-items: center;justify-content: space-between;padding: 30rpx;border-top: 1px solid #EFEFEF;">
			<view style="display: flex;flex-direction: row;align-items: center;">
				<image style="width: 50rpx;height: 50rpx;margin-right: 20rpx;" src="/static/common/pay/luggage-pay-wechat.png"></image>
				<text>微信支付</text>
			</view>
			<u-switch activeColor='#d4a781' v-model="isWxpay" @change="paywayChange('isWxpay')"></u-switch>
		</view>
		<!-- 提现按钮 -->
		<view class="confirm">
			<jc-button @click='confirmTap' style="margin-top: 100rpx" :width='690' title='确认付款' backgroundColor="#FC5E53"></jc-button>
		</view>
		
	</view>
</template>

<script>
	import {user} from '@/api/user.js'
	import {lessee} from '@/api/lessee.js'
	import {wallet} from '@/api/wallet.js'
	import {
		payway
	} from '@/api/payway.js'
	import {wxminiproPay} from '@/common/utils/wxminiproPay.js'
	export default{
		data() {
			return {
				shopId: '',
				shopName: '',
				isIncomes: false, //是否使用积分
				isWxpay: true,
				userInfo:{},
				totalPrice: '',
				totalPricePass: true,
				priceRule: "请输入大于零的数字",
				payWayIndex:0,
				typeList: [
					{
						name: '支付宝',
						key: 'ali'
					},{
						name: '微信',
						key: 'wx'
					},{
						name: '银行卡',
						key: 'bank'
					}]
			}
		},
		onLoad() {
		},
		onShow() {
			this.shopId = this.$Route.query.shopId
			this.shopName = this.$Route.query.shopName
			this.getUserInfo()
		},
		methods:{
			//选择支付方式
			paywayChange(e){
				console.log("选择支付方式", e)
				// this.currentPayway = index
				
				switch (e){
					case 'isWxpay':
						this.isBalance = false
						this.isIncomes = false
						this.isWxpay = true
						break;
					case 'isIncomes':
						this.isBalance = false
						this.isGolds = false
						this.isWxpay = false
						break;
					case 'isBalance':
						this.isIncomes = false
						this.isWxpay = false
						this.isBalance = true
						break;
					default:
						break;
				}
			},
			//确认提现金额
			payMoneyChange(e){
				var value = e.detail.value.replace(/\s/g, "")
				if(isNaN(value)){
					this.totalPricePass = false
				}else{
					this.totalPricePass = true
				}
				if(value){
					this.totalPrice = parseFloat(value)
				}else{
					this.totalPrice = 0
				}
			},
			//确认提现按钮
			confirmTap(){
				// if(!this.paywayInfo.id){
				// 	this.$show.showMessage('请选择收款账户')
				// 	return
				// }
				if(!this.totalPrice){
					this.$show.showMessage('请输入付款金额')
					return
				}
				let priceStr = String(this.totalPrice)
				var totalPriceList = priceStr.split('.')
				if(totalPriceList.length>2){
					this.$show.showMessage('输入金额格式不正确')
					return
				}
				if(totalPriceList.length==2 && totalPriceList[1].length>2){
					this.$show.showMessage('输入金额格式不正确，请保留小数点后两位')
					return
				}
				var that = this
			 	var params = {
					scene: 'payForFranchisee',
					shopId: this.shopId,
					sendType: 'noSend',
					realPay: this.totalPrice,
					remark: '加盟店付款'
				}
				var tostContent = ''
								
				if(this.isIncomes && this.isIncomesLocked){
					params.payway = 'incomeAndIncomeLocked'
				}else if(this.isIncomesLocked){
					params.payway = 'incomeLocked'
					tostContent = '本次支付将消耗'+this.totalPrice + '锁定积分'
				}else if(this.isIncomes){
					params.payway = 'incomes'
					tostContent = '本次支付将消耗'+this.totalPrice + '购物积分'
				}else if(this.isGolds){
					params.payway = 'golds'
				}else if(this.isBalance){
					params.payway = 'balance'
					tostContent = '本次支付将消耗'+this.totalPrice + '现金余额'
				}else if(this.isWxpay){
					params.payway = 'wxpay'
				}else{
					this.$show.showMessage('请选择支付方式')
					return
				}
				
				switch (params.payway){
					case 'balance':
						var _this = this
						uni.showModal({
							content: tostContent,
							confirmText: '确定',
							cancelText: '取消',
							complete(_res) {
								if(_res.confirm){
									_this.wxminiproPay(params)
								}
							}
						})
						break;
					case 'wxpay':
						this.wxminiproPay(params)
						break;
					default:
						var _this = this
						uni.showModal({
							content: tostContent,
							confirmText: '确定',
							cancelText: '取消',
							complete(_res) {
								if(_res.confirm){
									_this.wxminiproPay(params)
								}
							}
						})
						break;
				}
			},
			wxminiproPay(params){
				uni.showLoading({
					title: '加载中',
					mask: true
				})
				wxminiproPay(params).then(res => {
					uni.hideLoading()
					if(res.data.code == 10000){
						uni.showModal({
							content: '支付成功',
							confirmText: '确定',
							showCancel: false,
							complete(_res) {
								if(_res.confirm){
									uni.navigateBack()
								}
							}
						})
					}
				})
			},
			getUserInfo() {
				user.getUserInfo().then(res => {
					if (res.data.code == 10000) {
						this.userInfo = res.data.data
					}
				})
			},
		}
	}
</script>

<style lang="scss" scoped>
	.container{
		.payWay{
			display: flex;
			flex-direction: column;
			margin-top: 10rpx;
			background-color: #FFFFFF;
			.jifen{
				display: flex;
				flex-direction: row;
				justify-content: space-between;
				padding: 30rpx 30rpx;
				text-align: right;
			}
			.totalPrice{
				padding: 40rpx;
				text-align: right;
				background-color: #FFFFFF;
				text:nth-of-type(2){
					color: #FC5E53;
					font-size: 34rpx;
					font-weight: bold;
				}
				text:nth-of-type(3){
					font-size: 24rpx;
				}
			}
		}
	}
	.paywayItem{
		margin-top: 20rpx;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: space-between;
		background-color: #FFFFFF;
		padding: 30rpx 0rpx;
		padding-right: 20rpx;
		.center{
			width: 750rpx;
			display: flex;
			flex-direction: column;
			align-items: flex-start;
			.contactInfo{
				display: flex;
				flex-direction: row;
				align-items: center;
				.default{
					background-color: #FC5E53;
					color: #FFFFFF;
					font-size: 20rpx;
					width: 50rpx;
					height: 30rpx;
					margin-right: 10rpx;
					text-align: center;
					font-weight: bold;
				}
				text{
					margin-top: 10rpx;
				}
			}
			.paywayInfo{
				display: flex;
				flex-direction: column;
				align-items: flex-start;
			}
			.right{
				margin-right: 30rpx;
			}
		}
	}
	.payway_cont{
		background-color: #FFFFFF;
		margin-top: 30rpx;
		.content_item{
			display: flex;
			flex-direction: row;
			align-items: center;
			padding: 0 30px;
			.left{
				.isSelect{
					width: 36rpx;
					height: 36rpx;
					padding: 10rpx;
				}
			}
			.right{
				width: 100%;
				display: flex;
				flex-direction: column;
				margin-left: 20rpx;
				padding: 30rpx 0;
			}
			.bottomLine{
				border-bottom: 1px solid #EFEFEF
			}
		}
	}
	.confirmPayMoney{
		padding: 30rpx;
		display: flex;
		flex-direction: column;
		background-color: #FFFFFF;
		.title{
			font-size: 26rpx;
		}
		.input_con{
			display: flex;
			flex-direction: row;
			align-items: center;
			margin-top: 40rpx;
			// border-bottom: 1px #EFEFEF solid;
			text{
				margin-right: 20rpx;
				font-size: 44rpx;
				font-weight: bold;
			}
			input{
				width: 100%;
				font-size: 34rpx;
			}
		}
		text{
			
		}
	}
	.message{
		color: $st-color-primary;
		font-size: 22rpx;
		margin-top: 20rpx;
		padding: 0 20rpx;
	}
	.confirm{
		width: 100%;
		display: flex;
		flex-direction: column;
		align-items: center;
	}
</style>
